<?php
class LatestNewsWidget extends CWidget {

    //put your code here
    public $categoryId;
    public $count = 5;

    public function run() {
	if (!isset($this->categoryId)) {
	    throw new CException(Yii::t('zii', 'The "categoryId" property cannot be empty.'));
	}

	$assets = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias(
			'ext.LatestNews') . '/assets/css');
	// Register extension assets
	$cs = Yii::app()->getClientScript();
	$cs->registerCssFile($assets . '/LatestNews.css');

	$category = Category::model()->findByPk($this->categoryId);

	if ($category == null || empty($category)) {
	    
	    echo t('MSG_CATEGORY_NEWS_NOT_FOUND', 'messages');
	    //throw new CException(t('404', 'messages'));
	} else {
	
	$articleLatestNews = Article::model()->findLatestNews($this->categoryId, $this->count);
	
	$this->render('_latest_view', array('category' => $category, 'articles' => $articleLatestNews));
	}
    }

}

?>
